package com.samtech.primefaces.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.samtech.domain.EtAirport;
import com.samtech.primefaces.dao.EtAirportDao;

public class EtAirportJPADao implements EtAirportDao{

	@PersistenceContext
	protected EntityManager entityManager;
	
	public EntityManager getEntityManager() {
		return entityManager;
	}



	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}



	public void delete(EtAirport et) {
		//entityManager.remove(et);
		entityManager.createQuery("DELETE FROM "+EtAirport.class.getName()+" m WHERE m.airportCode=:id").setParameter("id", et.getAirportCode()).executeUpdate();

	}

	

	@SuppressWarnings("unchecked")
	public List<EtAirport> loadAll() {
		return entityManager.createQuery("select o from "+EtAirport.class.getName()+" as o ").getResultList();
		
	}

	public EtAirport loadById(String airportCode) {
		return entityManager.find(EtAirport.class, airportCode);
		
	}

	public void persist(EtAirport et) {
		entityManager.persist(et);
	}

	public void update(EtAirport et) {
		entityManager.merge(et);

	}

}
